<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="title">
            <h2><a href="#" class="back" onclick="history.go(-1)"/>Pesquisar Empresa</h2>
        </ui:define>

        <ui:define name="body">

            <p:panel styleClass="container_24 clearfix">
                <div class="buttonAction" style="float: right">
                    <p:button value="Adicionar" href="criarempresa.xhtml" icon="ui-icon-plusthick"
                              styleClass="ui-priority-primary"/>
                </div>
                <br/>
            </p:panel>

            <h:form id="empresaForm" enctype="multipart/form-data">            
                <p:messages id="messages" closable="true" showDetail="true" autoUpdate="true"  />

                <p:panel id="filtrosPanel" styleClass="container_24 clearfix">

                    <h2>Filtros</h2>

                    <f:validateBean disabled="true">
                        <p:outputLabel value="CNPJ:" styleClass="grid_3" for="cnpjInputMask"/>
                        <p:inputMask id="cnpjInputMask" value="#{managerPesquisarEmpresa.empresaPesquisar.cnpj}" 
                                     styleClass="grid_8" mask="99.999.999/9999-99" 
                                     autocomplete="false" />
                    </f:validateBean>
                    <div class="clear"/>

                    <p:outputLabel value="Nome Fantasia:" styleClass="grid_3 nomeFantasiaLabel" for="nomeFantasiaInputText"/>
                    <p:inputText id="nomeFantasiaInputText" 
                                 value="#{managerPesquisarEmpresa.empresaPesquisar.nomeFantasia}" 
                                 styleClass="grid_20"/>
                    <div class="clear"/>

                    <div class="buttonAction">
                        <p:commandButton value="Pesquisar" styleClass="ui-priority-primary"
                                         actionListener="#{managerPesquisarEmpresa.pesquisar()}"
                                         update=":empresaForm:empresaTable, :empresaForm:resultPanel"
                                         id="pesquisarCommandButton" icon="ui-icon-search"/>
                        <p:button href="indexempresa.xhtml" value="Cancelar" icon="ui-icon-circle-close"/>

                    </div>

                </p:panel>

                <p:panel id="resultPanel" styleClass="container_24 clearfix">
                    <p:dataTable id="empresaTable" var="item" value="#{managerPesquisarEmpresa.empresas}"
                                 paginator="true" paginatorPosition="bottom"
                                 styleClass="grid_24" emptyMessage="Nenhum registro" rowIndexVar="idempresa">  
                        <f:facet name="header">
                            Empresa
                        </f:facet>

                        <p:column headerText="Ação" width="50">
                            <p:button title="Visualizar"
                                      href="visualizarempresa.xhtml?vEmpresa=#{item.id}"
                                      icon="ui-icon-zoomin"/>
                            <p:commandButton update="@form" title="Excluir"
                                             oncomplete="dlg.show()"
                                             icon="ui-icon-trash" >
                                <f:setPropertyActionListener target="#{managerPesquisarEmpresa.empresaDelete}" value="#{item}" />
                            </p:commandButton>
                        </p:column>

                        <p:column headerText="CNPJ" width="100">
                            <h:outputText value="#{managerPesquisarEmpresa.cnpjMask(item.cnpj)}" />
                        </p:column>
                        <p:column headerText="Nome Fantasia">  
                            <h:outputText value="#{item.nomeFantasia}"/>
                        </p:column>
                        <p:column headerText="Responsáveis" style="white-space: pre-wrap;">  
                            <h:outputText value="#{managerPesquisarEmpresa.nomeResponsaveis(item.usuarios)}" />
                        </p:column>

                    </p:dataTable>

                </p:panel>

                <p:dialog id="modalDialog" header="Confirmação de remoção" widgetVar="dlg" modal="true" 
                          appendToBody="true"
                          height="80" closable="true" resizable="false" >
                    <h:outputText value="Tem certeza que deseja remover esta empresa?" />
                    <div class="buttonAction">
                        <p:commandButton value="Sim"
                                         actionListener="#{managerPesquisarEmpresa.deletar()}"
                                         update="@form" onsuccess="dlg.hide()"
                                         icon="ui-icon-check"/>
                        <p:commandButton value="Não" icon="ui-icon-circle-close"
                                         oncomplete="dlg.hide()" />

                    </div>
                </p:dialog>
            </h:form>
        </ui:define>
    </ui:composition>
</html>


